﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;
using System.Text;
using System.IO;
using GPCSC.Web.sjsbyes;

namespace GPCSC.Web.sjs
{
    public partial class Jpost : PageBase
    {
        public double[] ad = new double[26];
        public StringBuilder[] adds = new StringBuilder[26];
        public string add = "0";


        public double[] su = new double[26];
        public StringBuilder[] sums = new StringBuilder[26];
        public string asum = "0";
        public string cout = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int i = 0; i < 26; i++)
                {
                    adds[i] = new StringBuilder();
                    sums[i] = new StringBuilder();
                }
                string postid = Usual.f_querystringToString("postid");
                string kmonth = Usual.f_querystringToString("kmonth");
                string jmonth = Usual.f_querystringToString("jmonth");
                DataSet dsname = new Summ().PostUser(postid);
                sumss(dsname, "newSelAllbyuserid_km", kmonth, jmonth);
            }
        }
        protected void sumss(DataSet dsname, string sql, string kmonth, string jmonth)
        {


            if (dsname != null)
            {
                if (dsname.Tables.Count > 0)
                {
                    if (dsname.Tables[0].Rows.Count > 0)
                    {
                        PostListS.DataSource = dsname;
                        PostListS.DataBind();
                        cout = dsname.Tables[0].Rows.Count.ToString();
                        //循环遍历每个领导人
                        foreach (DataRow dr in dsname.Tables[0].Rows)
                        {
                            string userid = dr["CL_USER_SOID"].ToString();
                            Hashtable htables = new Hashtable();
                            htables.Add("@lgid", userid);
                            htables.Add("@year", Usual.f_requestParamsToInt("year"));
                            htables.Add("@kmonth", kmonth);
                            htables.Add("@jmonth", jmonth);
                            DataSet ds = new SqlReadXml().ReaderDataSet(sql, htables);
                            if (ds != null)
                            {
                                if (ds.Tables.Count > 0)
                                {
                                    if (ds.Tables[0].Rows.Count > 0)
                                    {
                                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                        {
                                            ad[0] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["zday"].ToString());//下基层活动天数
                                            ad[1] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["XJCDYTS"].ToString());//下基层调研
                                            ad[2] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZXMQRJPS"].ToString());//民情
                                            ad[3] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZCRHTS"].ToString());//走村入户
                                            ad[4] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZDZHTS"].ToString());//驻点住户
                                            ad[5] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["GKJFTS"].ToString());//公开接访天数
                                            ad[6] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["JDXFAJ"].ToString());//接待信访件数
                                            ad[7] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["yjaxf"].ToString());//已结案
                                            ad[8] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZDXFBAJS"].ToString());//重点信访
                                            ad[9] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZDXFBAJWCS"].ToString());//重点信访包案。。
                                            ad[10] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["KNQZZHS"].ToString());//已走访困难
                                            ad[11] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["WWKNQZQK_YZFHS"].ToString());//已走访挂钩。。
                                            ad[12] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["YBFHS"].ToString());// 已帮扶挂钩。。
                                            ad[13] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["WWJZZHLJJE"].ToString());//慰问捐助金额。。
                                            ad[14] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["ZKZTHCS"].ToString());
                                            ad[15] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["Z_CJRC"].ToString());
                                            ad[16] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["XSZCXJCS"].ToString());
                                            ad[17] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["X_CJRC"].ToString());
                                            ad[18] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["CJLDTS"].ToString());
                                            ad[19] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["WJCDWFCZJLJJE"].ToString());
                                            ad[25] += Usual.f_convertDobule(ds.Tables[0].Rows[i]["dybg"].ToString());
                                        }
                                        for (int i = 0; i < 20; i++)
                                        {
                                            adds[i].Append("<td  class=\"td\" >" + ad[i].ToString() + "</td>");
                                            
                                            su[i] += ad[i];
                                            ad[i] = 0;
                                        }
                                        adds[25].Append("<td  class=\"td\" >" + ad[25].ToString() + "</td>");
                                        su[25] += ad[25];
                                        ad[25] = 0;
                                    }
                                    else
                                    {
                                        for (int m = 0; m < 20; m++)
                                        {

                                            ad[m] = 0;
                                            adds[m].Append("<td  class=\"td\" >" + add + "</td>");
                                        }
                                        ad[25] = 0;
                                        adds[25].Append("<td  class=\"td\" >" + add + "</td>");
                                    }
                                }
                            }
                            adwt(dr["CL_USER_SOID"].ToString(), kmonth, jmonth);//问题总计
                            jjwt(dr["CL_USER_SOID"].ToString(), kmonth, jmonth);//解决问题统计
                            Bss(dr["CL_USER_SOID"].ToString(), kmonth, jmonth);//办实事
                            knAgg(dr["CL_USER_SOID"].ToString());


                        }
                        //合计值
                        for (int i = 0; i < 26; i++)
                        {

                            sums[i].Append("<td  class=\"td\" >" + su[i].ToString() + "</td>");
                        }
                    }
                }
            }
        }

        // 问题统计
        protected void adwt(string userid, string kmonth, string jmonth)
        {
            int wts = 0;
            Hashtable htable = new Hashtable();
            htable.Add("@lgid", userid);
            htable.Add("@year", DateTime.Now.Year);
            htable.Add("@kmonth", kmonth);
            htable.Add("@jmonth", jmonth);
            DataSet dwts = new SqlReadXml().ReaderDataSet("countWT", htable);
            if (dwts.Tables[0].Rows.Count > 0)
            {
                wts = Usual.f_convertInt32(dwts.Tables[0].Rows[0]["wts"].ToString());
            }
            adds[20].Append("<td  class=\"td\" >" + wts.ToString() + "</td>");
            su[20] += wts;
        }

        //解决问题统计
        protected void jjwt(string userid, string kmonth, string jmonth)
        {
            int wts = 0;
            Hashtable htable = new Hashtable();
            htable.Add("@lgid", userid);
            htable.Add("@year", DateTime.Now.Year);
            htable.Add("@kmonth", kmonth);
            htable.Add("@jmonth", jmonth);
            DataSet dwts = new SqlReadXml().ReaderDataSet("countjjWT", htable);
            if (dwts.Tables[0].Rows.Count > 0)
            {
                wts = Usual.f_convertInt32(dwts.Tables[0].Rows[0]["jwts"].ToString());
            }
            adds[21].Append("<td  class=\"td\" >" + wts.ToString() + "</td>");
            su[21] += wts;
        }
        //办实事情况
        protected void Bss(string userid, string kmonth, string jmonth)
        {
            int wts = 0;
            Hashtable htable = new Hashtable();
            htable.Add("@lgid", userid);
            htable.Add("@year", DateTime.Now.Year);
            htable.Add("@kmonth", kmonth);
            htable.Add("@jmonth", jmonth);
            DataSet dwts = new SqlReadXml().ReaderDataSet("counBss", htable);
            if (dwts.Tables[0].Rows.Count > 0)
            {
                wts = Usual.f_convertInt32(dwts.Tables[0].Rows[0]["jwts"].ToString());
            }
            adds[22].Append("<td  class=\"td\" >" + wts.ToString() + "</td>");
            su[22] += wts;
        }

        //困难及挂钩结对户数
        protected void knAgg(string userid)
        {
            int kns = 0;
            int ggs = 0;
            Hashtable htable = new Hashtable();
            htable.Add("@lgid", userid);
            DataSet dwts = new SqlReadXml().ReaderDataSet("selks", htable);
            if (dwts.Tables[0].Rows.Count > 0)
            {

                foreach (DataRow dr in dwts.Tables[0].Rows)
                {
                    kns += Usual.f_convertInt32(dr["knqzzhs"].ToString());
                    ggs += Usual.f_convertInt32(dr["ggjdhs"].ToString());

                }
            }
            adds[23].Append("<td  class=\"td\" >" + kns.ToString() + "</td>");
            su[23] += kns;
            adds[24].Append("<td  class=\"td\" >" + ggs.ToString() + "</td>");
            su[24] += ggs;

        }

    }
}